home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / multitsk / vid_scrn / vid_scrn.asm < prev    next >
Encoding:
Assembly Source File  |  1987-11-22  |  44.2 KB  |  1,131 lines

  1.  
  2.  Title vid_ screen Routines by Jerry Joplin [70441,2627] CIS
  3.  Page ,132
  4.  
  5.  Subttl Usage Notes and Segment Declarations
  6. COMMENT *
  7.  
  8.         The following routines are a set of direct video-memory access
  9.  routines. They are much faster than BIOS functions, yet maintain full
  10.  Microsoft Windows, DESQview, and Topview rules of __good_behaviour__.
  11.  Programs written using these techniques are fully capable of running
  12.  as a concurrently executing task in a well behaved window.
  13.  
  14.  These routines have been designed for the small and tiny memory models
  15.  of TURBOC Vers 1.0 and the small memory model for MSC Vers 4.0 and 5.0
  16.  
  17. *
  18.  
  19. _TEXT         segment byte public 'CODE'
  20. DGROUP        group _DATA,_BSS
  21.               assume cs:_TEXT,ds:DGROUP,ss:DGROUP
  22. _TEXT         ends
  23. _DATA         segment word public 'DATA'
  24. _DATA         ends
  25. _BSS          segment word public 'BSS'
  26. _BSS          ends
  27.  
  28. _TEXT         segment   byte public 'CODE'
  29.  
  30.               assume    cs:_TEXT, ds:DGROUP, es:nothing, ss:DGROUP
  31.  
  32.  
  33.  Page ,132
  34.  Subttl Procedure declarations
  35.  
  36.               public    _vid_puts            ;Write string w/attr
  37.               public    _vid_putc            ;Write character w/attr
  38.               public    _vid_readc           ;Read char/attr
  39.  
  40.               public    _vid_begin           ;Begin a video update
  41.               public    _vid_update          ;End a video update
  42.               public    _vid_buffc           ;Write a char/attr in an update
  43.  
  44.               public    _vid_memread         ;Video memory block read
  45.               public    _vid_memwrite        ;Video memory block write
  46.  
  47.               public    _vid_clearbox        ;Clear a window
  48.               public    _vid_scrollbox       ;Scroll a window
  49.               public    _vid_drawbox         ;Draw a box around a window
  50.               public    _vid_setbox          ;Set a box character set
  51.  
  52.               public    _vid_setpage         ;Set the active video page
  53.               public    _vid_setmode         ;Set the video mode
  54.               public    _vid_poscurs         ;Position the cursor
  55.  
  56.  
  57. Screen        equ       10h
  58.  
  59.  
  60.  Page ,132
  61.  Subttl Functions
  62.  
  63. ;-------------------------------------------------------------------------
  64. ;Write a null terminated string directly to Video memory
  65. ; If a virtual screen buffer is detected then write the
  66. ; string to the buffer and update the real display.
  67. ; If no virtual screen is detected then blast the string
  68. ; directly to video memory without snow for the CGA.
  69. ;-------------------------------------------------------------------------
  70.  
  71. StringOfs     equ       [bp+4]
  72. Row           equ       [bp+6]
  73. Col           equ       [bp+8]
  74. Attr          equ       [bp+10]
  75.  
  76. _vid_puts     proc      near
  77.  
  78.  
  79.               push      bp
  80.               mov       bp,sp                ;Address call parameters and
  81.               push      di                   ; save register variables
  82.               push      si
  83.  
  84.               mov       dh,byte ptr Row      ;Determine video address for
  85.               mov       dl,byte ptr Col      ; the specified row and column
  86.               call      GetVideoAddr         ; as Seg:Offs in ES:DI
  87.  
  88.               mov       si,StringOfs         ;Get the address of the string
  89.               mov       ah,Attr              ; and video attribute
  90.  
  91.               mov       bx,es
  92.               cmp       bx,0b000h            ;Video segment = Monochrome?
  93.               jz        Mono_Puts            ; yes, then this case is easy
  94.  
  95.               cmp       bx,0b800h            ;Video segment = Color?
  96.               jnz       Buff_Puts            ; no, then must be a shadow
  97.                                              ; buffer we are writing to
  98.  
  99. ;
  100. ;       Write string a Non-Monochrome video screen
  101. ;       accomodating CGA tendancy to snow
  102. ;
  103.  
  104. Puts_Next:
  105.               lodsb                          ;Load character of string
  106.               or        al,al                ;Is it end of the string?
  107.               jz        VS_Puts_Exit         ; yes, then exit.
  108.               mov       bx,ax                ;Save video word in BX
  109.               mov       dx,03dah             ;Prepare to read 6845
  110.               cli                            ; disable interrupts
  111. V_Retrace_Puts:
  112.               in        al,dx                ; get 6845 status
  113.               test      al,1000b             ;Vertical retrace bit set?
  114.               jnz       Write_Puts           ; yes, then write it
  115.               rcr       al,1                 ; no, wait till horizontal
  116.               jc        V_Retrace_Puts       ; retrace bit set
  117. H_Retrace_Puts:
  118.               in        al,dx                ;Get 6845 status again
  119.               rcr       al,1                 ; wait for horizontal
  120.               jnc       H_Retrace_Puts       ; retrace bit
  121. Write_Puts:
  122.               mov       ax,bx                ;Restore screen word
  123.               stosw                          ; and move it to the screen
  124.               sti                            ;Allow interrupts
  125.               jmp       short Puts_Next      ;Continue until null is hit
  126.  
  127. ;
  128. ;       Write string to a virtual screen buffer and
  129. ;       update the real screen
  130. ;
  131.  
  132.  
  133. Buff_Puts:
  134.               push      di                   ;Save beginning buffer offset
  135.               xor       cx,cx                ; use CX for character count
  136. BuffNext:
  137.               lodsb                          ; load next char into AL
  138.               or        al,al                ; is it the end of the string?
  139.               jz        BuffWriteExit        ; yes, then update buffer.
  140.               stosw                          ; else write it to screen
  141.               inc       cx                   ; and increment the char count
  142.               jmp       short BuffNext       ; continue with next char
  143.  
  144. BuffWriteExit:
  145.               pop       di                   ;Restore buffer offset
  146.               mov       ah,0ffh              ; Update the video buffer
  147.               int       Screen               ; with chars altered in CX
  148.               jmp       short VS_Puts_Exit   ; and exit.
  149.  
  150. ;
  151. ;       Write string to a monochrome screen
  152. ;
  153.  
  154.  
  155. Mono_Puts:
  156.               lodsb                          ;Load character into AL
  157.               or        al,al                ; is it the end of the string?
  158.               jz        VS_Puts_Exit         ; yes, then exit.
  159.               stosw                          ; else write it to screen
  160.               jmp       short Mono_Puts      ; continue till null.
  161.  
  162.  
  163. VS_Puts_Exit:
  164.  
  165.               pop       si
  166.               pop       di
  167.               pop       bp                   ;Restore registers
  168.               ret                            ; and return
  169.  
  170. _vid_puts     endp
  171.  
  172.  
  173. ;-------------------------------------------------------------------------
  174. ;Write a character directly to Video memory
  175. ; If a virtual screen buffer is detected then write the
  176. ; character to the buffer and update the real display.
  177. ; If no virtual screen is detected then write the character
  178. ; directly to video memory without snow for the CGA.
  179. ;-------------------------------------------------------------------------
  180.  
  181. Char          equ       [bp+4]
  182. Row           equ       [bp+6]
  183. Col           equ       [bp+8]
  184. Attr          equ       [bp+10]
  185.  
  186. _vid_putc     proc      near
  187.  
  188.               push      bp
  189.               mov       bp,sp                ;Address call parameters and
  190.               push      di                   ; save register variables
  191.               push      si
  192.  
  193.               mov       dh,byte ptr Row      ;Determine video address for
  194.               mov       dl,byte ptr Col      ; the specified row and column
  195.               call      GetVideoAddr         ; as Seg:Offs in ES:DI
  196.  
  197.               mov       al,Char              ;Get the character and
  198.               mov       ah,Attr              ; video attribute
  199.  
  200.               mov       bx,es
  201.               cmp       bx,0b000h            ;Video segment = Monochrome?
  202.               jz        Mono_Putc            ; yes, then use mono routine
  203.  
  204.               cmp       bx,0b800h            ;Video segment = Color?
  205.               jnz       Buff_Putc            ; no, then must be a shadow
  206.                                              ; buffer we are writing to
  207.  
  208. ;
  209. ;       Write character to a Non-Monochrome video screen
  210. ;       accomodating CGA tendancy to snow
  211. ;
  212.  
  213.               mov       bx,ax                ;Save video word in BX
  214.               mov       dx,03dah             ;Prepare to read 6845
  215.               cli                            ; disable interrupts
  216. V_Retrace_Putc:
  217.               in        al,dx                ; get 6845 status
  218.               test      al,1000b             ;Vertical retrace bit set?
  219.               jnz       Write_Putc           ; yes, then write it
  220.               rcr       al,1                 ; no, wait for horizonal
  221.               jc        V_Retrace_Putc       ; retrace bit
  222. H_Retrace_Putc:
  223.               in        al,dx                ;Get 6845 status again
  224.               rcr       al,1                 ; wait for horizontal
  225.               jnc       H_Retrace_Putc       ; retrace bit
  226. Write_Putc:
  227.               mov       ax,bx                ;Restore screen word
  228.               mov       es:[di],ax           ; and move it to the screen
  229.               sti                            ;Allow interrupts
  230.               jmp       short VS_Putc_Exit   ; and exit.
  231.  
  232. ;
  233. ;       Write a character to a virtual screen buffer and
  234. ;       update the real screen
  235. ;
  236.  
  237. Buff_Putc:
  238.               mov       es:[di],ax           ;Write the char/attribute
  239.               mov       cx,1
  240.               mov       ah,0ffh              ;Update the video buffers
  241.               int       Screen               ; one character change
  242.               jmp       short VS_Putc_Exit   ; and exit.
  243.  
  244. ;
  245. ;       Write a character to a monochrome screen
  246. ;
  247.  
  248. Mono_Putc:
  249.               mov       es:[di],ax           ;Write the char/attr to screen
  250.  
  251.  
  252. VS_Putc_Exit:
  253.  
  254.               pop       si
  255.               pop       di
  256.               pop       bp                   ;Restore registers
  257.               ret                            ; and return
  258.  
  259. _vid_putc     endp
  260.  
  261. ;-------------------------------------------------------------------------
  262. ;Read a character/attribute directly from Video memory
  263. ; If a virtual screen buffer is detected then read the
  264. ; character from the virtual screen buffer.
  265. ; If no virtual screen is detected then read the character
  266. ; directly from video memory without snow for the CGA.
  267. ;-------------------------------------------------------------------------
  268.  
  269. Row           equ       [bp+4]
  270. Col           equ       [bp+6]
  271.  
  272. _vid_readc    proc      near
  273.  
  274.               push      bp
  275.               mov       bp,sp                ;Address call parameters and
  276.               push      di                   ; save register variables
  277.               push      si
  278.  
  279.               mov       dh,byte ptr Row      ;Determine video address for
  280.               mov       dl,byte ptr Col      ; the specified row and column
  281.               call      GetVideoAddr         ; as Seg:Offs in ES:DI
  282.  
  283.  
  284.               mov       bx,es
  285.               cmp       bx,0b000h            ;Video segment = Monochrome?
  286.               jz        Mono_Readc           ; yes, then use mono routine
  287.  
  288.               cmp       bx,0b800h            ;Video segment = Color?
  289.               jnz       Buff_Readc           ; no, then must be a shadow
  290.                                              ; buffer we are reading from
  291.  
  292. ;
  293. ;       Read character from a Non-Monochrome video screen
  294. ;       accomodating CGA tendancy to snow
  295. ;
  296.  
  297.               mov       dx,03dah             ;Prepare to read 6845
  298.               cli                            ; disable interrupts
  299. V_Retrace_Readc:
  300.               in        al,dx                ; get 6845 status
  301.               test      al,1000b             ;Vertical retrace bit set?
  302.               jnz       Read_Readc           ; yes, then write it
  303.               rcr       al,1                 ; no, wait for horizontal
  304.               jc        V_Retrace_Readc      ; retrace bit
  305. H_Retrace_Readc:
  306.               in        al,dx                ;Get 6845 status again
  307.               rcr       al,1                 ; wait for horizontal
  308.               jnc       H_Retrace_Readc      ; retrace bit
  309. Read_Readc:
  310.               mov       ax,es:[di]           ; read char/attr from screen
  311.               sti                            ;Allow interrupts
  312.               jmp       short VS_Readc_Exit  ; and exit.
  313.  
  314.  
  315. ;
  316. ;       Read a character from a virtual screen buffer or
  317. ;       a monochrome display
  318. ;
  319.  
  320.  
  321. Buff_Readc:
  322.  
  323. Mono_Readc:                                  ;Monochrome and Virtual display
  324.               mov       ax,es:[di]           ; reads are simple memory transfers
  325.  
  326.  
  327. VS_Readc_Exit:
  328.  
  329.               pop       si
  330.               pop       di
  331.               pop       bp                   ;Restore registers
  332.               ret                            ; and return
  333.  
  334. _vid_readc    endp
  335.  
  336.  
  337. ;-------------------------------------------------------------------------
  338. ;Read a block of Video memory from a row and col into a save buffer
  339. ; If a virtual screen buffer is detected then read the
  340. ; block from the virtual screen buffer.
  341. ; If no virtual screen is detected then read the block
  342. ; directly from video memory without snow for the CGA.
  343. ;-------------------------------------------------------------------------
  344.  
  345. SaveBuff      equ       [bp+4]
  346. Row           equ       [bp+6]
  347. Col           equ       [bp+8]
  348. Count         equ       [bp+10]
  349.  
  350. _vid_memread  proc      near
  351.  
  352.               push      bp
  353.               mov       bp,sp                ;Address call parameters and
  354.               push      di                   ; save register variables
  355.               push      si
  356.               push      ds
  357.  
  358.               mov       dh,byte ptr Row      ;Determine video address for
  359.               mov       dl,byte ptr Col      ; the specified row and column
  360.               call      GetVideoAddr         ; as Seg:Offs in ES:DI
  361.  
  362.               mov       si,di                ;Screen will be Source for reads
  363.               mov       di,SaveBuff          ; destination is the Savebuff
  364.               mov       ax,ds                ; swap ES and DS
  365.               mov       bx,es                ; saving video segment in BX
  366.               mov       ds,bx
  367.               mov       es,ax
  368.  
  369.               cmp       bx,0b000h            ;Video segment = Monochrome?
  370.               jz        Mono_MemRead         ; yes, then use mono routine
  371.  
  372.               cmp       bx,0b800h            ;Video segment = Color?
  373.               jnz       Buff_MemRead         ; no, then must be a shadow
  374.                                              ; buffer we are reading from
  375.  
  376. ;
  377. ;       Read memory block from a Non-Monochrome video screen
  378. ;       accomodating CGA tendancy to snow
  379. ;
  380.  
  381.               mov       cx,Count
  382. Color_MemRead:
  383.  
  384.               mov       dx,03dah             ;Prepare to read 6845
  385.               cli                            ; disable interrupts
  386. V_Retrace_MemRead:
  387.               in        al,dx                ; get 6845 status
  388.               test      al,1000b             ;Vertical retrace bit set?
  389.               jnz       Read_MemRead         ; yes, then write it
  390.               rcr       al,1                 ; no, wait for horizontal
  391.               jc        V_Retrace_MemRead    ; retrace bit
  392. H_Retrace_MemRead:
  393.               in        al,dx                ;Get 6845 status again
  394.               rcr       al,1                 ; wait for horizontal
  395.               jnc       H_Retrace_MemRead    ; retrace bit
  396. Read_MemRead:
  397.               movsw                          ;Save this video char/attr
  398.               loop      Color_MemRead        ; and continue with next word
  399.               jmp       short VS_MemRead_Exit ; until through
  400.  
  401.  
  402.  
  403. ;
  404. ;       Read memory block from a virtual screen buffer or
  405. ;       a monochrome display
  406. ;
  407.  
  408.  
  409. Buff_MemRead:
  410.  
  411. Mono_MemRead:
  412.               mov       cx,Count             ;Monochrome and Virtual display
  413.               rep       movsw                ; reads are simple memory transfers
  414.  
  415. VS_MemRead_Exit:
  416.  
  417.               pop       ds
  418.               pop       si
  419.               pop       di
  420.               pop       bp                   ;Restore registers
  421.               ret                            ; and return
  422.  
  423. _vid_memread  endp
  424.  
  425.  
  426. ;-------------------------------------------------------------------------
  427. ;Write to a block of Video memory at a row and col from a buffer
  428. ; If a virtual screen buffer is detected then write to the
  429. ; virtual screen buffer and update the real screen.
  430. ; If no virtual screen is detected then write
  431. ; directly to video memory without snow for the CGA.
  432. ;-------------------------------------------------------------------------
  433.  
  434. SaveBuff      equ       [bp+4]
  435. Row           equ       [bp+6]
  436. Col           equ       [bp+8]
  437. Count         equ       [bp+10]
  438.  
  439. _vid_memwrite proc      near
  440.  
  441.               push      bp
  442.               mov       bp,sp                ;Address call parameters and
  443.               push      di                   ; save register variables
  444.               push      si
  445.  
  446.               mov       dh,byte ptr Row      ;Determine video address for
  447.               mov       dl,byte ptr Col      ; the specified row and column
  448.               call      GetVideoAddr         ; as Seg:Offs in ES:DI
  449.  
  450.               mov       si,SaveBuff          ;Source is the Savebuff
  451.  
  452.               mov       bx,es
  453.               cmp       bx,0b000h            ;Video segment = Monochrome?
  454.               jz        Mono_MemWrite        ; yes, then use mono routine
  455.  
  456.               cmp       bx,0b800h            ;Video segment = Color?
  457.               jnz       Buff_MemWrite        ; no, then must be a video buffer
  458.  
  459. ;
  460. ;       Write a memory block to a Non-Monochrome video screen
  461. ;       accomodating CGA tendancy to snow
  462. ;
  463.  
  464.               mov       cx,Count
  465. Color_MemWrite:
  466.  
  467.               mov       dx,03dah             ;Prepare to read 6845
  468.               cli                            ; disable interrupts
  469. V_Retrace_MemWrite:
  470.               in        al,dx                ; get 6845 status
  471.               test      al,1000b             ;Vertical retrace bit set?
  472.               jnz       Read_MemWrite        ; yes, then write it
  473.               rcr       al,1                 ; no, wait for horizontal
  474.               jc        V_Retrace_MemWrite   ; retrace bit
  475. H_Retrace_MemWrite:
  476.               in        al,dx                ;Get 6845 status again
  477.               rcr       al,1                 ; wait for horizontal
  478.               jnc       H_Retrace_MemWrite   ; retrace bit
  479. Read_MemWrite:
  480.               movsw                          ;Save this video char/attr
  481.               loop      Color_MemWrite       ; and continue with next char
  482.               jmp       short VS_MemWrite_Exit ; until through
  483.  
  484.  
  485. ;
  486. ;       Write a memory block to a virtual screen buffer and
  487. ;       update the real screen
  488. ;
  489.  
  490.  
  491. Buff_MemWrite:
  492.               push      di                   ;Save beginning buffer offset
  493.               mov       cx,Count             ; Load character count
  494.               rep       movsw                ; store the char/attr's
  495.               pop       di                   ; restore buffer offset
  496.               mov       cx,Count             ; use CX for character count
  497.               mov       ah,0ffh              ; Update the video buffer
  498.               int       Screen               ; with chars altered in CX
  499.               jmp       short VS_MemWrite_Exit  ; and exit.
  500.  
  501. ;
  502. ;       Write a memory block to a monochrome display
  503. ;
  504.  
  505.  
  506. Mono_MemWrite:
  507.               mov       cx,Count             ;Monochrome display writes
  508.               rep       movsw                ; are simple memory transfers
  509.  
  510. VS_MemWrite_Exit:
  511.  
  512.               pop       si
  513.               pop       di
  514.               pop       bp                   ;Restore registers
  515.               ret                            ; and return
  516.  
  517. _vid_memwrite endp
  518.  
  519.  
  520. ;-------------------------------------------------------------------------
  521. ;Start a video screen update
  522. ;-------------------------------------------------------------------------
  523.  
  524. _vid_begin    proc      near
  525.  
  526.               push      bp
  527.               mov       bp,sp                ;Address call parameters and
  528.               push      di                   ; save register variables
  529.               push      si
  530.  
  531.               mov       bx,0b000h            ;Assume monochrome adapter
  532.  
  533.               mov       ax,40h               ;Determine Screen Segment
  534.               mov       es,ax                ; address BIOS Data segment
  535.               cmp       byte ptr es:[49h],7  ; monochrome video mode?
  536.               jz        GotBeginSeg          ; yes, screen Seg is ok
  537.  
  538.               mov       bx,0b800h            ; no, set Non-Monochrome
  539.                                              ; segment address
  540. GotBeginSeg:
  541.               mov       es,bx                ; ES:DI = assumed video addr
  542.               xor       di,di
  543.  
  544.               mov       ah,0feh              ;Get our process video address
  545.               int       Screen
  546.  
  547.               mov       VideoSeg,es          ;Save the video memory address
  548.               mov       VideoOfs,di          ; for following buffer writes
  549.  
  550.               mov       StartOfs,0ffffh      ;Set the initial start offset to
  551.                                              ; large value, any writes will
  552.                                              ; be to an address below it
  553.               mov       EndOfs,di            ;Set the initial end offset to
  554.                                              ; start of video memory so any
  555.                                              ; write will be at higher address
  556.                                                                                           ; above it
  557.               pop       si
  558.               pop       di
  559.               pop       bp                   ;Restore registers
  560.               ret                            ; and return
  561.  
  562. _vid_begin    endp
  563.  
  564.  
  565. ;-------------------------------------------------------------------------
  566. ;End a video update
  567. ;-------------------------------------------------------------------------
  568.  
  569. _vid_update   proc      near
  570.  
  571.               push      bp
  572.               mov       bp,sp                ;Address call parameters and
  573.               push      di                   ; save register variables
  574.               push      si
  575.  
  576.               mov       es,VideoSeg          ;Retrieve the starting addr
  577.                                              ; of the beginning of the
  578.               mov       di,StartOfs          ; altered video memory
  579.               cmp       di,0ffffh            ; If nothing has been altered
  580.               jz        VS_Update_Exit       ; then theres nothing to update
  581.  
  582.               mov       cx,EndOfs            ;Calculate the number of
  583.               sub       cx,di                ; *characters* changed
  584.               shr       cx,1                 ; (EndOffs-StartOffs) / 2
  585.               inc       cx                   ; add 1 for round off
  586.  
  587.               mov       ah,0ffh              ;Update the video buffer
  588.               int       Screen               ; with chars altered in CX
  589.  
  590. VS_Update_Exit:
  591.  
  592.               pop       si
  593.               pop       di
  594.               pop       bp                   ;Restore registers
  595.               ret                            ; and return
  596.  
  597. _vid_update   endp
  598.  
  599.  
  600.  
  601. ;-------------------------------------------------------------------------
  602. ;Buffer a character to the process virtual screen
  603. ;-------------------------------------------------------------------------
  604.  
  605. Char          equ       [bp+4]
  606. Row           equ       [bp+6]
  607. Col           equ       [bp+8]
  608. Attr          equ       [bp+10]
  609.  
  610. _vid_buffc    proc      near
  611.  
  612.               push      bp
  613.               mov       bp,sp
  614.  
  615.               push      di
  616.               push      si
  617.  
  618.               mov       dh,byte ptr Row
  619.               mov       dl,byte ptr Col
  620.               mov       di,VideoOfs          ;Use values saved in vs_begin
  621.               mov       es,VideoSeg          ; as starting video address
  622.  
  623.               xor       ax,ax                ;Calculate screen offset
  624.               mov       al,dh                ; load row into AX and BX
  625.               mov       bx,ax
  626.               shl       ax,1                 ; avoid MUL instruction for
  627.               shl       ax,1                 ; slower 8088 based systems
  628.               shl       ax,1                 ; AX = row * 8
  629.               shl       bx,1                 ; BX = row * 2
  630.               add       bx,ax                ; BX = AX + BX = row * 10
  631.               shl       bx,1
  632.               shl       bx,1
  633.               shl       bx,1                 ; BX = row * 80
  634.               xor       dh,dh
  635.               add       bx,dx                ; BX = row * 80 + columns
  636.               shl       bx,1                 ; account for attribute bytes
  637.               add       di,bx
  638.  
  639.               mov       al,Char              ;Place attr/char in AX
  640.               mov       ah,Attr
  641.  
  642.               mov       bx,es
  643.               cmp       bx,0b000h            ;Use Mono Character display?
  644.               jz        Mono_Buffc           ; yes, then branch to it
  645.  
  646.               cmp       bx,0b800h            ;Use Color charcter display?
  647.               jnz       Buff_Buffc           ; no, then must be a shadow
  648.                                              ; buffer we are writing to
  649.  
  650.               mov       bx,ax                ;Save video word in BX
  651.               mov       dx,03dah             ;Prepare to read 6845
  652.               cli                            ; disable interrupts
  653. V_Retrace_Buffc:
  654.               in        al,dx                ; get 6845 status
  655.               test      al,1000b             ;Vertical retrace?
  656.               jnz       Write_Buffc          ; yes, then write it
  657.               rcr       al,1                 ; no, wait for end of
  658.               jc        V_Retrace_Buffc      ; horizontal retrace
  659. H_Retrace_Buffc:
  660.               in        al,dx                ;Get 6845 status again
  661.               rcr       al,1                 ; wait for horizontal
  662.               jnc       H_Retrace_Buffc      ; retrace
  663. Write_Buffc:
  664.               mov       ax,bx                ;Restore screen word
  665.               mov       es:[di],ax           ; and move it to the screen
  666.               sti                            ;Allow interrupts
  667.               jmp       short VS_Buffc_Exit
  668.  
  669.  
  670.  
  671. Buff_Buffc:
  672.               cmp       di,StartOfs          ;See if this offset is
  673.               jae       Ofs_greater          ; LESS than any previous
  674.               mov       StartOfs,di          ; since last call to vs_begin
  675.  
  676. Ofs_greater:
  677.               cmp       di,EndOfs            ;See if this offset is
  678.               jbe       Mono_Buffc           ; GREATER than any previous
  679.               mov       EndOfs,di            ; since last call to vs_begin
  680.  
  681. Mono_Buffc:
  682.               mov       es:[di],ax           ; store the attr/char
  683.  
  684. VS_Buffc_Exit:
  685.  
  686.               pop       si
  687.               pop       di
  688.               pop       bp                   ;Restore registers
  689.               ret                            ; and return
  690.  
  691. _vid_buffc    endp
  692.  
  693.  
  694.  
  695. ;-------------------------------------------------------------------------
  696. ;Draw a box to the process virtual screen
  697. ;-------------------------------------------------------------------------
  698.  
  699. TRow          equ       [bp+8]
  700. LCol          equ       [bp+10]
  701. BRow          equ       [bp+12]
  702. RCol          equ       [bp+14]
  703. Attr          equ       [bp+16]
  704. BorderType    equ       [bp+18]
  705. Next          equ       [bp-2]
  706.  
  707. _vid_drawbox  proc      near
  708.  
  709.               push      si
  710.               push      di                   ;Save register variables
  711.               push      bp
  712.               mov       bp,sp                ; address call stack
  713.               dec       sp
  714.               dec       sp                   ; allocate 1 word pointer variable
  715.  
  716.  
  717.               mov       si,LCol              ; SI used as column counter
  718.               mov       di,TRow              ; DI used as row counter
  719.  
  720.               mov       cx,BorderType        ;Get the address of the
  721.               lea       bx,border0           ; box character set
  722.               jcxz      BoxIndexGot          ; if set 0 then already got it
  723. GetBoxIndex:
  724.               add       bx,8                 ; else add 8 till we got it
  725.               loop      GetBoxIndex
  726. BoxIndexGot:
  727.               mov       Next,bx              ; save this address in Next
  728.  
  729.                                              ;The Top row of the Box
  730.               call      _vid_begin           ; lies in a contigious block
  731.                                              ; of screen memory so
  732.                                              ; start a screen update
  733. DrawTopLeft:
  734.               push      Attr                 ;Draw the top left character
  735.               push      si                   ; using vid_buffc
  736.               push      di
  737.               mov       bx,Next
  738.               push      [bx]
  739.               call      _vid_buffc
  740.               add       sp,8
  741.  
  742.               inc       word ptr Next        ;Point Next to next box char
  743. DrawTopLine:
  744.               inc       si                   ;Move SI to next column
  745.               cmp       si,word ptr RCol     ; hit the right side yet?
  746.               jae       DrawTopRight         ; yes, then draw top right
  747.  
  748.               push      Attr                 ;Draw chars of the top line
  749.               push      si                   ; using vid_buffc
  750.               push      di
  751.               mov       bx,word ptr Next
  752.               push      [bx]
  753.               call      _vid_buffc
  754.               add       sp,8
  755.               jmp       short DrawTopLine
  756.  
  757.  
  758. DrawTopRight:
  759.               inc       word ptr Next        ;Point Next to next box char
  760.  
  761.               push      Attr                 ;Draw the top right char
  762.               push      si                   ; using vid_buffc
  763.               mov       ax,di
  764.               push      ax
  765.               mov       bx,Next
  766.               push      [bx]
  767.               call      _vid_buffc
  768.               add       sp,8
  769.  
  770.               call      _vid_update          ;End this screen 'transaction'
  771.  
  772.  
  773.  
  774.               inc       word ptr Next        ;Point Next to next box char
  775. DrawRightLine:
  776.               inc       di                   ;Move DI next row
  777.               cmp       di,word ptr BRow     ; hit the bottom yet?
  778.               jae       DrawBottomRight      ; yes, then draw bottom right
  779.  
  780.               push      Attr                 ;Draw the characters of the
  781.               push      si                   ; right side using vid_putc
  782.               push      di                   ; since vertical lines
  783.               mov       bx,Next              ; do not lie in a contigious
  784.               push      [bx]                 ; block of screen memory
  785.               call      _vid_putc
  786.               add       sp,8
  787.               jmp       short DrawRightLine
  788.  
  789.  
  790. DrawBottomRight:                             ;The Bottom row of the Box
  791.               call      _vid_begin           ; lies in a contigious block
  792.                                              ; of screen memory so
  793.                                              ; start a screen update
  794.  
  795.               inc       word ptr Next        ;Point Next to next box char
  796.  
  797.               push      Attr                 ;Draw the bottom right
  798.               push      si                   ; character using vid_buffc
  799.               push      di
  800.               mov       bx,Next
  801.               push      [bx]
  802.               call      _vid_buffc
  803.               add       sp,8
  804.  
  805.               inc       word ptr Next        ;Point Next to next box char
  806. DrawBottomLine:
  807.  
  808.               dec       si                   ;Move SI to next column
  809.               cmp       si,word ptr LCol     ; hit the left side yet?
  810.               jbe       DrawBottomLeft       ; yes, then draw bottom left
  811.  
  812.               push      Attr                 ;Draw chars of the bottom
  813.               push      si                   ; line using vid_buffc
  814.               push      di
  815.               mov       bx,Next
  816.               push      [bx]
  817.               call      _vid_buffc
  818.               add       sp,8
  819.               jmp       short DrawBottomLine
  820.  
  821.  
  822. DrawBottomLeft:
  823.               inc       word ptr Next        ;Point Next to next box char
  824.  
  825.               push      Attr                 ;Draw the bottom left char
  826.               push      si                   ; using vid_buffc
  827.               push      di
  828.               mov       bx,Next
  829.               push      [bx]
  830.               call      _vid_buffc
  831.               add       sp,8
  832.  
  833.  
  834.  
  835.               call      _vid_update          ;End this screen 'transaction'
  836.  
  837.  
  838.               inc       word ptr Next        ;Point Next to next box char
  839. DrawLeftLine:
  840.               dec       di                   ;Move up to next row
  841.               cmp       di,word ptr TRow     ; hit top yet?
  842.               jbe       DrawBoxExit          ; yes, then box is thru
  843.  
  844.               push      Attr                 ;Draw the characters of the
  845.               push      si                   ; left side using vid_putc
  846.               push      di                   ; since vertical lines
  847.               mov       bx,Next              ; do not lie in a contigious
  848.               push      [bx]                 ; block of screen memory
  849.               call      _vid_putc
  850.               add       sp,8
  851.               jmp       short DrawLeftLine
  852.  
  853. DrawBoxExit:
  854.               mov       sp,bp
  855.               pop       bp
  856.               pop       di
  857.               pop       si
  858.               ret
  859. _vid_drawbox  endp
  860.  
  861. ;-------------------------------------------------------------------------
  862. ;Set a box rendition set
  863. ;-------------------------------------------------------------------------
  864.  
  865. BorderSet     equ       [bp+4]
  866. UpperLeft     equ       [bp+6]
  867. Top           equ       [bp+8]
  868. UpperRight    equ       [bp+10]
  869. Right         equ       [bp+12]
  870. LowerRight    equ       [bp+14]
  871. Bottom        equ       [bp+16]
  872. LowerLeft     equ       [bp+18]
  873. Left          equ       [bp+20]
  874.  
  875. _vid_setbox   proc      near
  876.  
  877.               push      bp
  878.               mov       bp,sp                ;Address call parameters and
  879.               push      di                   ; save register variables
  880.               push      si
  881.  
  882.               push      ds                   ;Extra segment = data segment
  883.               pop       es
  884.  
  885.               mov       cx,BorderSet         ;Get the address of the box
  886.               lea       di,border0           ; character set to establish
  887.               jcxz      BoxIndexSet          ; if set 0 then already got it
  888. SetBoxIndex:
  889.               add       di,8                 ; else add 8 till we hit it
  890.               loop      SetBoxIndex
  891. BoxIndexSet:
  892.  
  893.               lea       si,UpperLeft         ;Point Source index to new box set
  894.               mov       cx,8                 ; contains 8 characters
  895.               cld                            ; Lets be __forward__ shall we
  896.  
  897. GetBoxChars:  lodsw                          ;Get a word from stack
  898.               stosb                          ; and save the low order byte
  899.               loop      GetBoxChars          ; as a box character
  900.  
  901.               pop       si
  902.               pop       di
  903.               pop       bp                   ;Restore registers
  904.               ret                            ; and return
  905. _vid_setbox   endp
  906.  
  907.  
  908. ;-------------------------------------------------------------------------
  909. ;Clear a box on the video screen
  910. ; by invoking BIOS scroll window function
  911. ; specifying 0 lines to scroll
  912. ;-------------------------------------------------------------------------
  913.  
  914. Urow          equ       [bp+4]
  915. Lcol          equ       [bp+6]
  916. Brow          equ       [bp+8]
  917. Rcol          equ       [bp+10]
  918. Attr          equ       [bp+12]
  919.  
  920. _vid_clearbox proc      near
  921.               push      bp
  922.               mov       bp,sp                ;Address call parameters and
  923.               push      di                   ; save register variables
  924.               push      si
  925.  
  926.               mov       ax,0600h             ;Use BIOS scroll window up function
  927.                                              ; AL = 0 to blank area
  928.               jmp       short BIOS_Scroll
  929.  
  930. _vid_clearbox endp
  931.  
  932.  
  933. ;-------------------------------------------------------------------------
  934. ;Scroll a box on the video screen
  935. ; a specified direction and number of lines
  936. ; by invoking BIOS scroll window function
  937. ;-------------------------------------------------------------------------
  938.  
  939. Urow          equ       [bp+4]
  940. Lcol          equ       [bp+6]
  941. Brow          equ       [bp+8]
  942. Rcol          equ       [bp+10]
  943. Attr          equ       [bp+12]
  944. Direction     equ       [bp+14]
  945. NumberOfLines equ       [bp+16]
  946.  
  947. _vid_scrollbox proc     near
  948.               push      bp
  949.               mov       bp,sp                ;Address call parameters and
  950.               push      di                   ; save register variables
  951.               push      si
  952.                                              ;Use BIOS scroll window up function
  953.               mov       ah,Direction         ; valid directions are 0 and 1
  954.               add       ah,6                 ; function 6 is up, 7 is down
  955.               mov       al,NumberOfLines     ; AL holds number of scroll lines
  956.  
  957. BIOS_Scroll:
  958.               mov       bh,byte ptr Attr     ; BH holds video attribute
  959.               mov       ch,byte ptr Urow
  960.               mov       cl,byte ptr Lcol     ; CH:CL = top left
  961.               mov       dh,byte ptr Brow     ; DH:DL = bottom right
  962.               mov       dl,byte ptr Rcol
  963.               int       screen               ; transfer to BIOS
  964.  
  965.               pop       si
  966.               pop       di
  967.               pop       bp                   ;Restore registers
  968.               ret                            ; and return
  969.  
  970. _vid_scrollbox endp
  971.  
  972.  
  973.  
  974. ;-------------------------------------------------------------------------
  975. ;Set the active video page
  976. ;-------------------------------------------------------------------------
  977.  
  978. Vpage         equ       [bp+4]
  979.  
  980. _vid_setpage  proc      near
  981.               push      bp
  982.               mov       bp,sp                ;Address call parameters and
  983.               push      di                   ; save register variables
  984.               push      si
  985.  
  986.               mov       al,byte ptr Vpage    ;Get specified page
  987.               mov       VideoPage,al         ; save it to avoid overhead of
  988.                                              ; get video page requests
  989.  
  990.               mov       ah,5                 ;Use BIOS set video page function
  991.               int       screen               ; transfer to BIOS
  992.  
  993.               pop       si
  994.               pop       di
  995.               pop       bp                   ;Restore registers
  996.               ret                            ; and return
  997.  
  998. _vid_setpage  endp
  999.  
  1000. ;-------------------------------------------------------------------------
  1001. ;Establish the video mode
  1002. ;-------------------------------------------------------------------------
  1003.  
  1004. Vmode         equ       [bp+4]
  1005.  
  1006. _vid_setmode  proc      near
  1007.               push      bp
  1008.               mov       bp,sp                ;Address call parameters and
  1009.               push      di                   ; save register variables
  1010.               push      si
  1011.  
  1012.               mov       al,byte ptr Vmode    ;Get specified mode
  1013.               xor       ah,ah                ;Use BIOS set video mode function
  1014.               int       screen               ; transfer to BIOS
  1015.  
  1016.               pop       si
  1017.               pop       di
  1018.               pop       bp                   ;Restore registers
  1019.               ret                            ; and return
  1020.  
  1021. _vid_setmode  endp
  1022.  
  1023. ;-------------------------------------------------------------------------
  1024. ;Set the cursor to a position on the active video page
  1025. ;-------------------------------------------------------------------------
  1026.  
  1027. Row           equ       [bp+4]
  1028. Col           equ       [bp+6]
  1029.  
  1030.  
  1031. _vid_poscurs  proc      near
  1032.               push      bp
  1033.               mov       bp,sp                ;Address call parameters and
  1034.               push      di                   ; save register variables
  1035.               push      si
  1036.  
  1037.               mov       ah,2                 ;Use BIOS set cursor pos function
  1038.               mov       bh,VideoPage         ; in the saved video page
  1039.               mov       dh,byte ptr Row      ; DH:DL holds position
  1040.               mov       dl,byte ptr Col
  1041.               int       screen               ;Transfer to BIOS
  1042.  
  1043.               pop       si
  1044.               pop       di
  1045.               pop       bp                   ;Restore registers
  1046.               ret                            ; and return
  1047.  
  1048. _vid_poscurs  endp
  1049.  
  1050.  
  1051.  
  1052. ;-------------------------------------------------------------------------
  1053. ;Retrieve the video buffer address
  1054. ; On Entry:
  1055. ;      DX = row in DH, column in DL
  1056. ; Returns
  1057. ;      ES:DI video buffer address
  1058. ;-------------------------------------------------------------------------
  1059.  
  1060. GetVideoAddr  proc      near
  1061.  
  1062.               mov       bx,0b000h            ;Assume monochrome adapter
  1063.  
  1064.               mov       ax,40h               ;Determine Screen Segment
  1065.               mov       es,ax                ; address BIOS Data segment
  1066.               cmp       byte ptr es:[49h],7  ; monochrome video mode?
  1067.               jz        GotScreenAddr        ; yes, screen Seg is ok
  1068.  
  1069.               mov       bx,0b800h            ; no, set Non-Monochrome
  1070.                                              ; segment address
  1071. GotScreenAddr:
  1072.               mov       es,bx                ; ES:DI =assumed video addr
  1073.               xor       di,di
  1074.  
  1075.               mov       ah,0feh              ;Get our process video
  1076.               int       Screen               ; memory address
  1077.  
  1078.               xor       ax,ax                ;Calculate screen offset
  1079.               mov       al,dh                ; load row into AX and BX
  1080.               mov       bx,ax
  1081.               shl       ax,1                 ; avoid MUL instruction for
  1082.               shl       ax,1                 ; slower 8088 based systems
  1083.               shl       ax,1                 ; AX = row * 8
  1084.               shl       bx,1                 ; BX = row * 2
  1085.               add       bx,ax                ; BX = AX + BX = row * 10
  1086.               shl       bx,1
  1087.               shl       bx,1
  1088.               shl       bx,1                 ; BX = row * 80
  1089.               xor       dh,dh
  1090.               add       bx,dx                ; BX = row * 80 + columns
  1091.               shl       bx,1                 ; account for attribute bytes
  1092.  
  1093.               add       di,bx                ;Add the row and column offset
  1094.                                              ; to the video address offset
  1095.               ret                            ; and return
  1096.  
  1097. GetVideoAddr  endp
  1098.  
  1099.  
  1100. _TEXT         ends
  1101.  
  1102. ;-------------------------------------------------------------------------
  1103. ;vid_ routines data
  1104. ;-------------------------------------------------------------------------
  1105.  
  1106. _DATA         segment
  1107.  
  1108.  
  1109. StartOfs      dw        0ffffh               ;Starting offset in an update
  1110. Endofs        dw        ?                    ;Ending offset in an update
  1111. VideoOfs      dw        0                    ;Saved Offset and Segment pointer
  1112. VideoSeg      dw        ?                    ; to the video screen in an update
  1113.  
  1114. VideoPage     db        0                    ;Holds the current video page
  1115.  
  1116.                                              ;Box character sets, defaults:
  1117. border0       db        8 dup (' ')          ; 0 = spaces
  1118. border1       db        218,196,191,179,217,196,192,179 ; 1 =single line border,
  1119. border2       db        201,205,187,186,188,205,200,186 ; 2 =double line border.
  1120. border3       db        8 dup (0)
  1121. border4       db        8 dup (0)
  1122. border5       db        8 dup (0)            ; 3 - 7 should be set using
  1123. border6       db        8 dup (0)            ; vid_setbox before using
  1124. border7       db        8 dup (0)
  1125.  
  1126. _DATA         ends
  1127.  
  1128.  
  1129.               end
  1130.  
  1131.